//
//  XXJTarBar.m
//  不得姐
//
//  Created by 许小军 on 16/9/1.
//  Copyright © 2016年 wyzc. All rights reserved.
//

#import "XXJTarBar.h"
@interface XXJTarBar ()
@property(nonatomic,strong)UIButton * plusButton;
@property(weak,nonatomic)UIControl * previousClickedBtn;
@end
@implementation XXJTarBar
-(UIButton *)plusButton
{
    if (!_plusButton) {
        _plusButton=[[UIButton alloc]init];
        [_plusButton setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_icon"] forState:UIControlStateNormal];
        [_plusButton setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_click_icon"] forState:UIControlStateSelected];
        [_plusButton sizeToFit];
    }
    return _plusButton;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    int btnW=self.frame.size.width/(self.items.count+1);
    int btnH=self.frame.size.height;
    int btnY=0;
    int i=0;
    
    for (UIControl * tabBtn in self.subviews) {
        if ([tabBtn isKindOfClass:NSClassFromString(@"UITabBarButton")])
        {
            if (i==0 && _previousClickedBtn==nil) {
                _previousClickedBtn=tabBtn;
            }
            if (i==2) {
                i+=1;
            }
            tabBtn.frame=CGRectMake(btnW*i, btnY, btnW, btnH);
            i++;
            
            [tabBtn addTarget:self action:@selector(tabBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        }
    }
    self.plusButton.center=CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2);
    [self addSubview:_plusButton];
    
    
}

-(void)tabBtnClick:(UIControl *)tabBarBtn
{
    if (_previousClickedBtn==tabBarBtn) {
        [[NSNotificationCenter defaultCenter]postNotificationName:tabBarBtnDoubleClick object:nil];
    }
    _previousClickedBtn=tabBarBtn;
}

@end








